package com.ruoyi.rpt.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.rpt.domain.RptDefinition;
import com.ruoyi.rpt.service.IRptDefinitionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 报表定义Controller
 * 
 */
@RestController
@RequestMapping("/rpt/definition")
public class RptDefinitionController extends BaseController
{
    @Autowired
    private IRptDefinitionService rptDefinitionService;

    /**
     * 查询报表定义列表
     */
    // @RequiresPermissions("rpt:definition:list")
    @GetMapping("/list")
    public TableDataInfo list(RptDefinition rptDefinition)
    {
        startPage();
        List<RptDefinition> list = rptDefinitionService.selectRptDefinitionList(rptDefinition);
        return getDataTable(list);
    }

    /**
     * 导出报表定义列表
     */
    // @RequiresPermissions("rpt:definition:export")
    @Log(title = "报表定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RptDefinition rptDefinition)
    {
        List<RptDefinition> list = rptDefinitionService.selectRptDefinitionList(rptDefinition);
        ExcelUtil<RptDefinition> util = new ExcelUtil<RptDefinition>(RptDefinition.class);
        util.exportExcel(response, list, "报表定义数据");
    }

    /**
     * 获取报表定义详细信息
     */
    // @RequiresPermissions("rpt:definition:query")
    @GetMapping(value = "/{reportId}")
    public AjaxResult getInfo(@PathVariable("reportId") Long reportId)
    {
        return success(rptDefinitionService.selectRptDefinitionByReportId(reportId));
    }

    /**
     * 新增报表定义
     */
    // @RequiresPermissions("rpt:definition:add")
    @Log(title = "报表定义", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RptDefinition rptDefinition)
    {
        return toAjax(rptDefinitionService.insertRptDefinition(rptDefinition));
    }

    /**
     * 修改报表定义
     */
    // @RequiresPermissions("rpt:definition:edit")
    @Log(title = "报表定义", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RptDefinition rptDefinition)
    {
        return toAjax(rptDefinitionService.updateRptDefinition(rptDefinition));
    }

    /**
     * 删除报表定义
     */
    // @RequiresPermissions("rpt:definition:remove")
    @Log(title = "报表定义", businessType = BusinessType.DELETE)
	@DeleteMapping("/{reportIds}")
    public AjaxResult remove(@PathVariable Long[] reportIds)
    {
        return toAjax(rptDefinitionService.deleteRptDefinitionByReportIds(reportIds));
    }
} 